<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
</head>
<body>
  <script>
    /**
     * 输入年月日，输出该天为该年的第几天
     * 
     * */
    var now = new Date()
    var year = now.getFullYear()
    // 如果isRunYear为true时表明这年是闰年，闰年2月份是29天，非闰年2月份是28天
    var isRunYear = false
    if(Number.isInteger(year/4)&&!Number.isInteger(year/100)){
      isRunYear = true
    }
    var month = now.getMonth()+1
    var day = now.getDate()
    var i = 1
    var count = 0
    while (i < month) {
      switch (i) {
        case 1: case 3: case 5: case 7:case 8: case 10:case 12:
          count+=31
          break;
        case 2:
          isRunYear?count+=29:count+=28
          break;
        case 4: case 6: case 9: case 11:
          count+=30
          break;
      }
      i++
    }       
    console.log('今天是今年的第几天：',count+day);


    /**
     * 单词反转
     * 输入：I love sports
     * 输出：sports love I
     * */
    var str = 'I love sports'
    var arr = str.split(' ')
    for(let i = 0;i<=Math.floor(arr.length/2);i++){
      var temp = arr[i]
      arr[i] = arr[arr.length-i-1]
      arr[arr.length-i-1] = temp
    }
    console.log(arr.join(' '));


    /**
     * 输入一个数组和一个整数，问这个数组相邻元素之间相加减，可否得到目标整数
     * 输入：[1,2,5,7,9],12
     * */
    var arr2 = [1,2,5,7,9]; var flag = 12
    var arr3 = arr2.sort((a,b)=>{
      return a-b
    })
    for(let i = 0;i<arr3.length-1;i++){
      if(arr3[i]+arr3[i+1]===flag){
        console.log(i)
      }
    }
  </script>
</body>
</html>